<?php


namespace app\api\controller;


use logicmodel\UserLogic;
use logicmodel\WxLogic;
use think\Request;
use validate\AuthValidate;

class User extends BaseController
{
    private $userLogic;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->userLogic = new UserLogic();
    }

    /**
     * 个人信息
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function userInfo(){
        return json($this->userLogic->userInfo($this->userInfo));
    }

    /**
     * 编辑个人信息
     * @param $nick_name
     * @param $head_image
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function editUserInfo($nick_name,$head_image){
        return json($this->userLogic->editUserInfo($this->uid,$nick_name,$head_image));
    }

    /**
     * 绑定手机号
     * @param $phone
     * @param $code
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function bindPhone($phone,$code){
        return json($this->userLogic->bindPhone($this->userInfo,$phone,$code));
    }
    /**
     * 邀请分享
     * @return \think\response\Json
     * @throws \think\Exception
     */
    public function share(){
        return json($this->userLogic->share($this->userInfo));
    }

    /**
     * 修改登录密码
     * @param $code
     * @param $password
     * @param $password_re
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function updatePassword($code,$password,$password_re){
        return json($this->userLogic->updatePassword($this->userInfo,$code,$password,$password_re));
    }

    /**
     * 修改登录密码
     * @param $code
     * @param $pay_password
     * @param $pay_password_re
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function updatePayPassword($code,$password,$password_re){
        return json($this->userLogic->updatePayPassword($this->userInfo,$code,$password,$password_re));
    }
    /**
     * 团队信息
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function team(){
        return json($this->userLogic->team($this->uid));
    }

    /**
     * 微信授权
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function auth(){
        return json((new WxLogic())->userAuth($this->userInfo));
    }

    /**
     * 问题反馈
     * @param $images
     * @param $remark
     * @return \think\response\Json
     */
    public function feedBack($images,$remark){
        return json($this->userLogic->feedBack($this->uid,$images,$remark));
    }

    /**
     * 反馈列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function feedBackList(){
        return json($this->userLogic->feedBackList($this->uid));
    }

    /**
     * 实名认证
     * @param $name
     * @param $card
     * @return \think\response\Json
     * @throws \app\lib\exception\ParamException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function userAuth($name,$card){
        (new AuthValidate())->goCheck();
        return json($this->userLogic->userAuth($this->userInfo,$name,$card));
    }
}